home *** CD-ROM | disk | FTP | other *** search
- package javax.crypto;
-
- import java.io.IOException;
- import java.security.AlgorithmParameters;
- import java.security.GeneralSecurityException;
- import java.security.InvalidKeyException;
- import java.security.Key;
- import java.security.NoSuchAlgorithmException;
- import java.security.NoSuchProviderException;
- import java.security.Provider;
- import java.security.Security;
- import java.security.spec.InvalidKeySpecException;
- import java.security.spec.PKCS8EncodedKeySpec;
- import sun.security.util.DerInputStream;
- import sun.security.util.DerOutputStream;
- import sun.security.util.DerValue;
- import sun.security.x509.AlgorithmId;
-
- public class EncryptedPrivateKeyInfo {
- // $FF: renamed from: a sun.security.x509.AlgorithmId
- private AlgorithmId field_0;
- // $FF: renamed from: b byte[]
- private byte[] field_1;
- // $FF: renamed from: c byte[]
- private byte[] field_2 = null;
-
- public EncryptedPrivateKeyInfo(byte[] var1) throws IOException {
- if (var1 == null) {
- throw new NullPointerException("the encoded parameter must be non-null");
- } else {
- this.field_2 = (byte[])var1.clone();
- DerValue var2 = new DerValue(this.field_2);
- DerValue[] var3 = new DerValue[]{var2.data.getDerValue(), var2.data.getDerValue()};
- if (var2.data.available() != 0) {
- throw new IOException("overrun, bytes = " + var2.data.available());
- } else {
- this.field_0 = AlgorithmId.parse(var3[0]);
- if (var3[0].data.available() != 0) {
- throw new IOException("encryptionAlgorithm field overrun");
- } else {
- this.field_1 = var3[1].getOctetString();
- if (var3[1].data.available() != 0) {
- throw new IOException("encryptedData field overrun");
- }
- }
- }
- }
- }
-
- public EncryptedPrivateKeyInfo(String var1, byte[] var2) throws NoSuchAlgorithmException {
- if (var1 == null) {
- throw new NullPointerException("the algName parameter must be non-null");
- } else {
- this.field_0 = AlgorithmId.get(var1);
- if (var2 == null) {
- throw new NullPointerException("the encryptedData parameter must be non-null");
- } else if (var2.length == 0) {
- throw new IllegalArgumentException("the encryptedData parameter must not be empty");
- } else {
- this.field_1 = (byte[])var2.clone();
- this.field_2 = null;
- }
- }
- }
-
- public EncryptedPrivateKeyInfo(AlgorithmParameters var1, byte[] var2) throws NoSuchAlgorithmException {
- if (var1 == null) {
- throw new NullPointerException("algParams must be non-null");
- } else {
- this.field_0 = AlgorithmId.get(var1);
- if (var2 == null) {
- throw new NullPointerException("encryptedData must be non-null");
- } else if (var2.length == 0) {
- throw new IllegalArgumentException("the encryptedData parameter must not be empty");
- } else {
- this.field_1 = (byte[])var2.clone();
- this.field_2 = null;
- }
- }
- }
-
- public String getAlgName() {
- return this.field_0.getName();
- }
-
- public AlgorithmParameters getAlgParameters() {
- return this.field_0.getParameters();
- }
-
- public byte[] getEncryptedData() {
- return (byte[])this.field_1.clone();
- }
-
- public PKCS8EncodedKeySpec getKeySpec(Cipher var1) throws InvalidKeySpecException {
- Object var2 = null;
-
- try {
- var8 = var1.doFinal(this.field_1);
- method_2(var8);
- } catch (GeneralSecurityException var5) {
- InvalidKeySpecException var10 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
- var10.initCause(var5);
- throw var10;
- } catch (IOException var6) {
- InvalidKeySpecException var9 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
- var9.initCause(var6);
- throw var9;
- } catch (IllegalStateException var7) {
- InvalidKeySpecException var4 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
- var4.initCause(var7);
- throw var4;
- }
-
- return new PKCS8EncodedKeySpec(var8);
- }
-
- // $FF: renamed from: a (java.security.Key, java.security.Provider) java.security.spec.PKCS8EncodedKeySpec
- private PKCS8EncodedKeySpec method_0(Key var1, Provider var2) throws NoSuchAlgorithmException, InvalidKeyException {
- Object var3 = null;
-
- try {
- Cipher var4;
- if (var2 == null) {
- var4 = Cipher.getInstance(this.field_0.getName());
- } else {
- var4 = Cipher.getInstance(this.field_0.getName(), var2);
- }
-
- var4.init(2, var1, this.field_0.getParameters());
- var10 = var4.doFinal(this.field_1);
- method_2(var10);
- } catch (NoSuchAlgorithmException var7) {
- throw var7;
- } catch (GeneralSecurityException var8) {
- InvalidKeyException var11 = new InvalidKeyException("Cannot retrieve the PKCS8EncodedKeySpec");
- var11.initCause(var8);
- throw var11;
- } catch (IOException var9) {
- InvalidKeyException var6 = new InvalidKeyException("Cannot retrieve the PKCS8EncodedKeySpec");
- var6.initCause(var9);
- throw var6;
- }
-
- return new PKCS8EncodedKeySpec(var10);
- }
-
- public PKCS8EncodedKeySpec getKeySpec(Key var1) throws NoSuchAlgorithmException, InvalidKeyException {
- if (var1 == null) {
- throw new NullPointerException("decryptKey is null");
- } else {
- return this.method_0(var1, (Provider)null);
- }
- }
-
- public PKCS8EncodedKeySpec getKeySpec(Key var1, String var2) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
- if (var1 == null) {
- throw new NullPointerException("decryptKey is null");
- } else if (var2 == null) {
- throw new NullPointerException("provider is null");
- } else {
- Provider var3 = Security.getProvider(var2);
- if (var3 == null) {
- throw new NoSuchProviderException("provider " + var2 + " not found");
- } else {
- return this.method_0(var1, var3);
- }
- }
- }
-
- public PKCS8EncodedKeySpec getKeySpec(Key var1, Provider var2) throws NoSuchAlgorithmException, InvalidKeyException {
- if (var1 == null) {
- throw new NullPointerException("decryptKey is null");
- } else if (var2 == null) {
- throw new NullPointerException("provider is null");
- } else {
- return this.method_0(var1, var2);
- }
- }
-
- public byte[] getEncoded() throws IOException {
- if (this.field_2 == null) {
- DerOutputStream var1 = new DerOutputStream();
- DerOutputStream var2 = new DerOutputStream();
- this.field_0.encode(var2);
- var2.putOctetString(this.field_1);
- var1.write((byte)48, var2);
- this.field_2 = var1.toByteArray();
- }
-
- return (byte[])this.field_2.clone();
- }
-
- // $FF: renamed from: a (sun.security.util.DerValue, byte, java.lang.String) void
- private static void method_1(DerValue var0, byte var1, String var2) throws IOException {
- if (var0.getTag() != var1) {
- throw new IOException("invalid key encoding - wrong tag for " + var2);
- }
- }
-
- // $FF: renamed from: a (byte[]) void
- private static void method_2(byte[] var0) throws IOException {
- DerInputStream var1 = new DerInputStream(var0);
- DerValue[] var2 = var1.getSequence(3);
- switch (var2.length) {
- case 4:
- method_1(var2[3], (byte)-128, "attributes");
- case 3:
- method_1(var2[0], (byte)2, "version");
- DerInputStream var3 = var2[1].toDerInputStream();
- var3.getOID();
- if (var3.available() != 0) {
- var3.getDerValue();
- }
-
- method_1(var2[2], (byte)4, "privateKey");
- return;
- default:
- throw new IOException("invalid key encoding");
- }
- }
- }
-